package com.liu.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.liu.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class GoodsController {

    @Autowired
    StockService service;

    @SentinelResource(value = "查询商品",fallback = "fallback")
    @GetMapping("/goods")
    public Map get(){
        Map map = new HashMap();
        map.put("code",111);
        map.put("msg","查询商品");
        map.put("stock",service.queryStock());
        return map;
    }

    public Map fallback(){
        Map map = new HashMap();
        map.put("code",200);
        map.put("msg","限流了将资源给关联资源了!");
        return map;
    }

}
